package com.pdf;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 生成一个PDF
 * @author liyiruo
 * @Description
 * @Date 2021/8/10 下午3:23
 */
public class DemoPDF {
    static String path = "src/main/java/com/pdf/pdfData/";
    static String basePath = "src/main/java/com/pdf/";

    public static void main(String[] args) throws DocumentException, IOException {

        //获取路径的方式
        System.out.println(System.getProperty("user.dir"));
        System.out.println(new File("").getAbsolutePath());
        System.out.println(new File("").getCanonicalPath());

        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(path + "DemoPDF.pdf"));
        document.open();
        document.add(new Paragraph("Hello World"));
        document.close();
    }
}
